<?php
/**
 * Created by PhpStorm.
 * User: tjjs
 * Date: 17-7-18
 * Time: 下午1:29
 */

namespace Actions;

use Data\Order_form_DAO;
use Data\Order_for_foods_DAO;
use Data\Food_DAO;

class RestaurantOrderFormListFinished extends BaseAction
{
    public function doAction() {
        parent::doAction();
        // 商铺id
        $restaurant_id = $_SESSION[RESTAURANT_ID];
        $restaurant_id = 1;
        // 日期
        $date = $this->data[DATE];
        if (!$date) {
            $date = date("Y-m-d");
        }

        //
        $pay_status = STATE_YES;
        // 已完成订单列表
        $order_form_list_finished = Order_form_DAO::getListByResIdAndDate($restaurant_id,$date,$pay_status);

        foreach ($order_form_list_finished as $order_form_list_finished_record) {
            $order_form_id = $order_form_list_finished_record->getORDER_FORM_ID();
            // 订单中商品信息
            $order_for_food_list = Order_for_foods_DAO::getListByOrderFormId($order_form_id);
            foreach ($order_for_food_list as $key=>$order_for_food_record) {
                $food_id = $order_for_food_record[FOOD_ID];
                $food_name = Food_DAO::getName($food_id);
                $order_for_food_list[$key][FOOD_NAME] = $food_name;
            }
            // 订单全部信息
            $order_info[] = array(ORDER_FORM_INFO=>$order_form_list_finished_record->getArray(),ORDER_FOR_FOOD_INFO=>$order_for_food_list);
        }

        // 返回数据
        $this->setValue(ORDER_FORM_FINISHED_LIST,$order_info);
        $this->ResponseDataToCurrentClient();
    }
}